package model;

import java.awt.List;
import java.io.Serializable;
import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.GregorianCalendar;

import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;

public class User implements Serializable {
	private static final long serialVersionUID = 1L;
	// ArrayList
	private ArrayList<Call> arrCallLogs = null;
	private ArrayList<Sms> arrSmsLogs = null;
	ArrayList arrIncomingSMS = new ArrayList<>();
	ArrayList arrOutgoingSMS = new ArrayList<>();
	ArrayList arrIncomingCall = new ArrayList<>();
	ArrayList arrOutgoingCall = new ArrayList<>();

	double probabiltysms_call;
	int numdaycall, numdaysms;

	public int getNumdaycall() {
		return numdaycall;
	}

	public void setNumdaycall(int numdaycall) {
		this.numdaycall = numdaycall;
	}

	public int getNumdaysms() {
		return numdaysms;
	}

	public void setNumdaysms(int numdaysms) {
		this.numdaysms = numdaysms;
	}

	int sms_amount = 0, // tổng số lượng tin nhắn
			call_amount = 0,// tổng số lượng cuộc gọi
			incomingcallamount = 0,// tổng số lượng cuộc gọi đến
			outgoingcallamount = 0,// tổng số lượng cuộc gọi đi
			incomingsmsamount = 0,// tổng số lượng tin nhắn đến
			outgoingsmsamount = 0, // tổng số lượng tin nhắn đi
			misscallamount = 0, // tổng số lượng cuộc gọi nhỡ
			failcallamount = 0, // tong so luong cuoc goi loi
			lengthlyCallamount,// tổng số lượng cuộc gọi dài (2X)
			call_duration_total, // tổng thời lượng cuộc gọi
			sms_length_total, // tổng độ dài tin nhắn
			samegender;// cùng giới tính
	int maxDurIncomingCall, // thời lượng gọi đến lớn nhất
			maxDurOutgoingCall;// thời lượng gọi đến lớn nhất
	double avgIncomingSMS, // trung bình tin nhắn đến
			avgOutgoingSMS,// trung bình tin nhắn đi
			stdIncomingSMS,// độ lệch chuẩn tin nhắn đi
			stdOutgoinSMS,// độ lệch chuẩn tin nhắn đến
			minIncomingSMS,// số lượng tin nhắn đến nhỏ nhất
			minOutgoingSMS;
	private String imei;
	private String id;
	private int callrank, smsrank;
	private double differentBetweenSms, differentBettweenCall;

	public double getDifferentBetweenSms() {
		return differentBetweenSms;
	}

	public void setDifferentBetweenSms(double differentBetweenSms) {
		this.differentBetweenSms = differentBetweenSms;
	}

	public double getDifferentBettweenCall() {
		return differentBettweenCall;
	}

	public void setDifferentBettweenCall(double differentBettweenCall) {
		this.differentBettweenCall = differentBettweenCall;
	}

	public int getCallrank() {
		return callrank;
	}

	public void setCallrank(int callrank) {
		this.callrank = callrank;
	}

	public int getSmsrank() {
		return smsrank;
	}

	public void setSmsrank(int smsrank) {
		this.smsrank = smsrank;
	}

	public void calcNumDayCall_SMS() {
		ArrayList list = new ArrayList<>();
		ArrayList list3 = new ArrayList<>();
		for (int i = 0; i < this.arrCallLogs.size(); i++) {
			if (!list.contains(this.arrCallLogs.get(i).getDate())) {
				list.add(this.arrCallLogs.get(i).getDate());
			}
			if (!list3.contains(this.arrCallLogs.get(i).getDate())) {
				list3.add(this.arrCallLogs.get(i).getDate());
			}
		}
		ArrayList list2 = new ArrayList<>();
		for (int i = 0; i < this.arrSmsLogs.size(); i++) {
			if (!list2.contains(this.arrSmsLogs.get(i).getDate())) {
				list2.add(this.arrSmsLogs.get(i).getDate());
			}
			if (!list3.contains(this.arrSmsLogs.get(i).getDate())) {
				list3.add(this.arrSmsLogs.get(i).getDate());
			}
		}

		this.numdaycall = list.size();
		this.numdaysms = list2.size();
		this.numdaycomms = list3.size();
	}

	double sms_length_average, call_duration_average, sms_callProb,
			duroutgoingcall_totalprob, durincomingcallVtotalprob,
			lenoutgoingsms_totalProb, lenincomingsmsVtotalProb,
			totalCallV2WeekTotal, totalCallV2MonthTotal, totalSMSV2WeekTotal,
			totalSMSV2MonthTotal, durCallV2MonthTotal, durCallV2WeekTotal,
			lenSMSV2MonthTotal, lenSMSV2WeekTotal, COMMS2WEEKTOTAL,
			COMMS2MONTHTOTAL;

	String mostdayinweek;
	String mosthourinday;
	String relationshipLabel;
	String relationshipLabelProcessed;
	Contact contactdetail;
	double medianOutgoingSMS, lengSMSinEveCompareTotal;

	int hour[];
	private String smsmostdayinweek;
	private String callmostdayinweek;
	private String relationshipLabelProcessed2;

	// Chênh lệch tuổi, là bạn facebook
	// đã có trong ContactDetail

	// Đặc trưng
	// cá nhân Tương đồng {họ, tên miền email, tên công ty}; có {ảnh, ghi chú,
	// work phone, home phone, email}; được gắn sao; sự kiện
	// đặc trưng không sử dụng được

	// Tổng{số lượng, thời lượng} cuộc gọi, tổng số lượng cuộc gọi dài.

	// {tổng số lượng, thời lượng} cuộc gọi đi/tổng số cuộc gọi

	// {tổng số cuộc gọi, thời lượng} cuộc gọi {2 tuần trước, 3 tháng
	// trước}/tổng số cuộc gọi
	public void calcMaintaincost() {
		int numcall2week = 0, numcall2month = 0, numsms2week = 0, numsms2month = 0, durCall2week = 0, durCall2month = 0, lensms2week = 0, lensms2month = 0;
		int totalDur = 0, totalLen = 0;
		for (int t = 0; t < this.arrCallLogs.size(); t++) {
			// check 2 month
			if (checkTwoMonth(this.arrCallLogs.get(t).getDate())) {
				numcall2month++;
				durCall2month += this.arrCallLogs.get(t).getDuration();
			}
			// check 2 week
			if (checkTwoWeek(this.arrCallLogs.get(t).getDate())) {
				numcall2week++;
				durCall2week += this.arrCallLogs.get(t).getDuration();

			}
			totalDur += this.arrCallLogs.get(t).getDuration();

		}
		for (int t = 0; t < this.arrSmsLogs.size(); t++) {
			// check 2 month
			if (checkTwoMonth(this.arrSmsLogs.get(t).getDate())) {
				numsms2month++;
				lensms2month += this.arrSmsLogs.get(t).getLength();
			}
			// check 2 week
			if (checkTwoWeek(this.arrSmsLogs.get(t).getDate())) {
				numsms2week++;
				lensms2week += this.arrSmsLogs.get(t).getLength();

			}

			totalLen += this.arrSmsLogs.get(t).getLength();
		}
		if (arrCallLogs != null && numcall2week > 0 && durCall2week > 0) {
			this.totalCallV2WeekTotal = (double) numcall2week
					/ (double) this.arrCallLogs.size();
			this.durCallV2WeekTotal = (double) durCall2week / (double) totalDur;
		}
		// else {
		// this.totalCallV2WeekTotal = -1.0;
		// this.durCallV2WeekTotal = -1.0;
		// }
		if (arrCallLogs != null && numcall2month > 0 && durCall2month > 0) {
			this.totalCallV2MonthTotal = (double) numcall2month
					/ (double) this.arrCallLogs.size();
			this.durCallV2MonthTotal = (double) durCall2month
					/ (double) totalDur;
		}
		// else {
		// this.totalCallV2MonthTotal = -1.0;
		// this.durCallV2MonthTotal = -1.0;
		//
		// }

		if (arrSmsLogs != null && numsms2week > 0) {
			this.totalSMSV2WeekTotal = (double) numsms2week
					/ (double) this.arrSmsLogs.size();
			this.lenSMSV2WeekTotal = (double) lensms2week / (double) totalLen;
		}
		// else {
		// this.totalSMSV2WeekTotal = 1.0;
		// this.lenSMSV2WeekTotal = 1.0;
		// }
		if (arrSmsLogs != null && numsms2month > 0) {
			this.totalSMSV2MonthTotal = (double) numsms2month
					/ (double) this.arrSmsLogs.size();

			this.lenSMSV2MonthTotal = (double) lensms2month / (double) totalLen;

		}
		// else {
		// this.totalSMSV2MonthTotal = -1.0;
		// this.lenSMSV2MonthTotal = -1.0;
		// }
		if (this.arrCallLogs != null || this.arrSmsLogs != null
				&& (this.arrCallLogs.size() + this.arrSmsLogs.size()) > 0) {
			this.COMMS2WEEKTOTAL = (double) (numcall2week + numsms2week)
					/ (double) (this.arrCallLogs.size() + this.arrSmsLogs
							.size());
			this.COMMS2MONTHTOTAL = (double) (numcall2month + numsms2month)
					/ (double) (this.arrCallLogs.size() + this.arrSmsLogs
							.size());
		}
		// else {
		// this.COMMS2WEEKTOTAL = -1.0;
		// this.COMMS2MONTHTOTAL = -1.0;
		// }
	}

	// Tổng số tin nhắn {số lượng, độ dài}

	// {tổng số lượng, thời lượng} tin nhắn đi/tổng số tin nhắn

	// {tổng số tin nhắn, thời lượng} tin nhắn {2 tuần trước, 3 tháng
	// trước}/tổng số tin nhắn

	// Tổng số liên lạc

	// Số ngày có liên lạc/số ngày sử dụng

	public double getCOMMS2WEEKTOTAL() {
		return COMMS2WEEKTOTAL;
	}

	public void setCOMMS2WEEKTOTAL(double cOMMS2WEEKTOTAL) {
		COMMS2WEEKTOTAL = cOMMS2WEEKTOTAL;
	}

	public double getCOMMS2MONTHTOTAL() {
		return COMMS2MONTHTOTAL;
	}

	public void setCOMMS2MONTHTOTAL(double cOMMS2MONTHTOTAL) {
		COMMS2MONTHTOTAL = cOMMS2MONTHTOTAL;
	}

	public double getTotalCallV2MonthTotal() {
		return totalCallV2MonthTotal;
	}

	public void setTotalCallV2MonthTotal(double totalCallV2MonthTotal) {
		this.totalCallV2MonthTotal = totalCallV2MonthTotal;
	}

	public double getTotalSMSV2MonthTotal() {
		return totalSMSV2MonthTotal;
	}

	public void setTotalSMSV2MonthTotal(double totalSMSV2MonthTotal) {
		this.totalSMSV2MonthTotal = totalSMSV2MonthTotal;
	}

	public double getDurCallV2MonthTotal() {
		return durCallV2MonthTotal;
	}

	public void setDurCallV2MonthTotal(double durCallV2MonthTotal) {
		this.durCallV2MonthTotal = durCallV2MonthTotal;
	}

	public double getDurCallV2WeekTotal() {
		return durCallV2WeekTotal;
	}

	public void setDurCallV2WeekTotal(double durCallV2WeekTotal) {
		this.durCallV2WeekTotal = durCallV2WeekTotal;
	}

	public double getLenSMSV2MonthTotal() {
		return lenSMSV2MonthTotal;
	}

	public void setLenSMSV2MonthTotal(double lenSMSV2MonthTotal) {
		this.lenSMSV2MonthTotal = lenSMSV2MonthTotal;
	}

	public double getLenSMSV2WeekTotal() {
		return lenSMSV2WeekTotal;
	}

	public void setLenSMSV2WeekTotal(double lenSMSV2WeekTotal) {
		this.lenSMSV2WeekTotal = lenSMSV2WeekTotal;
	}

	// Liên lạc đi/tổng liên lạc, tổng cuộc gọi/tổng liên lạc
	private double outCOMMs_COMMs, calls_COMMs;
	private double failcall_outcall;
	private double misscall_incall;
	private double outSmsTotal;
	private double outSmsLenTotal;
	private int totalSmsLen = 0;
	private double numCallAtEvening_Total = 0;
	private double numCallAtMorning_Total = 0;
	private double numCallAtAfternoon_Total = 0;
	private double numCallAtNight_Total = 0;
	private double numSmsAtNight_Total = 0;
	private double numSmsAtEvening_Total = 0;
	private double numSmsAtMorning_Total = 0;
	private double numSmsAtAfternoon_Total = 0;
	private double numCommAtNight_Total;
	private double numCommAtEvening_Total;
	private double numCommAtMorning_Total;
	private double numCommAtAfternoon_Total;
	private double durCallAtNight_Total;
	private double durCallAtEvening_Total;
	private double durCallAtMorning_Total;
	private double durCallAtAfternoon_Total;
	private double lenSmsAtNight_Total;
	private double lenSmsAtEvening_Total;
	private double lenSmsAtMorning_Total;
	private double lenSmsAtAfternoon_Total;
	private double avg_dur_at_sunday;
	private double avg_dur_at_saturday;
	private double avg_dur_at_friday;
	private double avg_dur_at_workday;
	private double num_call_at_sunday_prob;
	private double num_call_at_Satday_prob;
	private double num_call_at_Friday_prob;
	private double num_call_at_Workday_prob;
	private double avg_len_at_sunday;
	private double avg_len_at_saturday;
	private double avg_len_at_friday;
	private double avg_len_at_workday;
	private double num_sms_at_sunday_prob;
	private double num_sms_at_Satday_prob;
	private double num_sms_at_Friday_prob;
	private double num_sms_at_Workday_prob;

	public void calcOutCOMMs_COMMsANDcalls_COMMs() {
		int outCOMMs = 0;
		for (int t = 0; t < this.arrCallLogs.size(); t++) {
			if (this.arrCallLogs.get(t).getCalltype().equals(Call.OUTGOING)) {
				outCOMMs++;
			}
		}
		for (int t = 0; t < this.arrSmsLogs.size(); t++) {
			if (this.arrSmsLogs.get(t).getSmstype().equals(Call.OUTGOING)) {

				outCOMMs++;
			}
		}
		this.calls_COMMs = (double) this.arrCallLogs.size()
				/ (double) (this.arrCallLogs.size() + this.arrSmsLogs.size());
		this.outCOMMs_COMMs = (double) outCOMMs
				/ (double) (this.arrCallLogs.size() + this.arrSmsLogs.size());
	}

	public void calcAverageDurationCallAtDayOfWeek() {
		int durSun = 0, durSat = 0, durFri = 0, durWork = 0, totalDur = 0;
		int numSun = 0, numSat = 0, numFri = 0, numWork = 0;

		if (this.arrCallLogs != null && this.arrCallLogs.size() > 0) {
			for (int i = 0; i < this.arrCallLogs.size(); i++) {
				Date calldate = this.arrCallLogs.get(i).getDate();
				if (isSunday(calldate)) {
					durSun += this.arrCallLogs.get(i).getDuration();
					numSun++;
				} else if (isSaturday(calldate)) {
					durSat += this.arrCallLogs.get(i).getDuration();
					numSat++;
				} else if (isFriday(calldate)) {
					durFri += this.arrCallLogs.get(i).getDuration();
					numFri++;
				} else if (isWorkday(calldate)) {
					durWork += this.arrCallLogs.get(i).getDuration();
					numWork++;
				}
				
				totalDur+=this.arrCallLogs.get(i).getDuration();;
				
			}
		}

		this.avg_dur_at_sunday = (double) durSun / (double) totalDur;
		
		this.avg_dur_at_saturday = (double) durSat / (double) totalDur;
		
		this.avg_dur_at_friday = (double) durFri / (double) totalDur;
		
		this.avg_dur_at_workday = (double) durWork / (double) totalDur;
		
		this.num_call_at_sunday_prob = (double) numSun
				/ (double) this.arrCallLogs.size();
		this.num_call_at_Satday_prob = (double) numSat
				/ (double) this.arrCallLogs.size();
		this.num_call_at_Friday_prob = (double) numFri
				/ (double) this.arrCallLogs.size();
		this.num_call_at_Workday_prob = (double) numWork
				/ (double) this.arrCallLogs.size();
		
		int lenSun = 0, lenSat = 0, lenFri = 0, lenWork = 0, totallen = 0;
		numSun = 0; numSat = 0; numFri = 0; numWork = 0;

		if (this.arrSmsLogs != null && this.arrSmsLogs.size() > 0) {
			for (int i = 0; i < this.arrSmsLogs.size(); i++) {
				Date Smsdate = this.arrSmsLogs.get(i).getDate();
				if (isSunday(Smsdate)) {
					lenSun += this.arrSmsLogs.get(i).getLength();
					numSun++;
				} else if (isSaturday(Smsdate)) {
					lenSat += this.arrSmsLogs.get(i).getLength();
					numSat++;
				} else if (isFriday(Smsdate)) {
					lenFri += this.arrSmsLogs.get(i).getLength();
					numFri++;
				} else if (isWorkday(Smsdate)) {
					lenWork += this.arrSmsLogs.get(i).getLength();
					numWork++;
				}
				
				totallen+=this.arrSmsLogs.get(i).getLength();
				
			}
		}

		this.avg_len_at_sunday = (double) lenSun / (double) totallen;
		
		this.avg_len_at_saturday = (double) lenSat / (double) totallen;
		
		this.avg_len_at_friday = (double) lenFri / (double) totallen;
		
		this.avg_len_at_workday = (double) lenWork / (double) totallen;
		
		this.num_sms_at_sunday_prob = (double) numSun
				/ (double) this.arrSmsLogs.size();
		this.num_sms_at_Satday_prob = (double) numSat
				/ (double) this.arrSmsLogs.size();
		this.num_sms_at_Friday_prob = (double) numFri
				/ (double) this.arrSmsLogs.size();
		this.num_sms_at_Workday_prob = (double) numWork
				/ (double) this.arrSmsLogs.size();

	}

	public double getAvg_len_at_sunday() {
		return avg_len_at_sunday;
	}

	public void setAvg_len_at_sunday(double avg_len_at_sunday) {
		this.avg_len_at_sunday = avg_len_at_sunday;
	}

	public double getAvg_len_at_saturday() {
		return avg_len_at_saturday;
	}

	public void setAvg_len_at_saturday(double avg_len_at_saturday) {
		this.avg_len_at_saturday = avg_len_at_saturday;
	}

	public double getAvg_len_at_friday() {
		return avg_len_at_friday;
	}

	public void setAvg_len_at_friday(double avg_len_at_friday) {
		this.avg_len_at_friday = avg_len_at_friday;
	}

	public double getAvg_len_at_workday() {
		return avg_len_at_workday;
	}

	public void setAvg_len_at_workday(double avg_len_at_workday) {
		this.avg_len_at_workday = avg_len_at_workday;
	}

	public double getNum_sms_at_sunday_prob() {
		return num_sms_at_sunday_prob;
	}

	public void setNum_sms_at_sunday_prob(double num_sms_at_sunday_prob) {
		this.num_sms_at_sunday_prob = num_sms_at_sunday_prob;
	}

	public double getNum_sms_at_Satday_prob() {
		return num_sms_at_Satday_prob;
	}

	public void setNum_sms_at_Satday_prob(double num_sms_at_Satday_prob) {
		this.num_sms_at_Satday_prob = num_sms_at_Satday_prob;
	}

	public double getNum_sms_at_Friday_prob() {
		return num_sms_at_Friday_prob;
	}

	public void setNum_sms_at_Friday_prob(double num_sms_at_Friday_prob) {
		this.num_sms_at_Friday_prob = num_sms_at_Friday_prob;
	}

	public double getNum_sms_at_Workday_prob() {
		return num_sms_at_Workday_prob;
	}

	public void setNum_sms_at_Workday_prob(double num_sms_at_Workday_prob) {
		this.num_sms_at_Workday_prob = num_sms_at_Workday_prob;
	}

	public double getNum_call_at_sunday_prob() {
		return num_call_at_sunday_prob;
	}

	public void setNum_call_at_sunday_prob(double num_call_at_sunday_prob) {
		this.num_call_at_sunday_prob = num_call_at_sunday_prob;
	}

	public double getNum_call_at_Satday_prob() {
		return num_call_at_Satday_prob;
	}

	public void setNum_call_at_Satday_prob(double num_call_at_Satday_prob) {
		this.num_call_at_Satday_prob = num_call_at_Satday_prob;
	}

	public double getNum_call_at_Friday_prob() {
		return num_call_at_Friday_prob;
	}

	public void setNum_call_at_Friday_prob(double num_call_at_Friday_prob) {
		this.num_call_at_Friday_prob = num_call_at_Friday_prob;
	}

	public double getNum_call_at_Workday_prob() {
		return num_call_at_Workday_prob;
	}

	public void setNum_call_at_Workday_prob(double num_call_at_Workday_prob) {
		this.num_call_at_Workday_prob = num_call_at_Workday_prob;
	}

	public double getAvg_dur_at_workday() {
		return avg_dur_at_workday;
	}

	public void setAvg_dur_at_workday(double avg_dur_at_workday) {
		this.avg_dur_at_workday = avg_dur_at_workday;
	}

	public double getAvg_dur_at_sunday() {
		return avg_dur_at_sunday;
	}

	public void setAvg_dur_at_sunday(double avg_dur_at_sunday) {
		this.avg_dur_at_sunday = avg_dur_at_sunday;
	}

	public double getAvg_dur_at_saturday() {
		return avg_dur_at_saturday;
	}

	public void setAvg_dur_at_saturday(double avg_dur_at_saturday) {
		this.avg_dur_at_saturday = avg_dur_at_saturday;
	}

	public double getAvg_dur_at_friday() {
		return avg_dur_at_friday;
	}

	public void setAvg_dur_at_friday(double avg_dur_at_friday) {
		this.avg_dur_at_friday = avg_dur_at_friday;
	}

	public boolean isSunday(Date date) {
		Calendar cal = new GregorianCalendar();
		cal.setTime(date);
		if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
			return true;
		}
		return false;
	}

	public boolean isSaturday(Date date) {
		Calendar cal = new GregorianCalendar();
		cal.setTime(date);
		if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
			return true;
		}
		return false;
	}

	public boolean isFriday(Date date) {
		Calendar cal = new GregorianCalendar();
		cal.setTime(date);
		if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {
			return true;
		}
		return false;
	}

	public boolean isWorkday(Date date) {
		Calendar cal = new GregorianCalendar();
		cal.setTime(date);
		if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
				|| cal.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY
				|| cal.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY
				|| cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
			return true;
		}
		return false;
	}

	// Liên lạc trong {2 tuần trước, 3 tháng trước}/tổng số liên lạc

	public double getOutCOMMs_COMMs() {
		return outCOMMs_COMMs;
	}

	public void setOutCOMMs_COMMs(double outCOMMs_COMMs) {
		this.outCOMMs_COMMs = outCOMMs_COMMs;
	}

	public double getCalls_COMMs() {
		return calls_COMMs;
	}

	public void setCalls_COMMs(double calls_COMMs) {
		this.calls_COMMs = calls_COMMs;
	}

	public int getSamegender() {
		return samegender;
	}

	public void setSamegender(int samegender) {
		this.samegender = samegender;
	}

	public String getImei() {
		return imei;
	}

	public void setImei(String imei) {
		this.imei = imei;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getLengthlyCallamount() {
		return lengthlyCallamount;
	}

	public void setLengthlyCallamount(int lengthlyCallamount) {
		this.lengthlyCallamount = lengthlyCallamount;
	}

	public int calcLengthlyCall() {
		int callnum = 0;
		for (int i = 0; i < arrCallLogs.size(); i++) {
			if (arrCallLogs.get(i).getDuration() > 120) {
				// (2 * this.call_duration_average)) {
				callnum++;
			}
		}
		return callnum;
	}

	public int getCall_duration_total() {
		return call_duration_total;
	}

	public int calcCall_duration_total() {
		int total = 0;
		for (int i = 0; i < this.arrCallLogs.size(); i++) {
			total += this.arrCallLogs.get(i).getDuration();
		}
		return total;
	}

	public void setCall_duration_total(int call_duration_total) {
		this.call_duration_total = call_duration_total;
	}

	public void calcSms_duration_total() {
		if (arrSmsLogs != null) {
			int total = 0, out = 0;
			int len = 0;
			for (int i = 0; i < this.arrSmsLogs.size(); i++) {
				total += this.arrSmsLogs.get(i).getLength();
				if (this.arrSmsLogs.get(i).getSmstype().equals(Sms.OUTGOING)) {
					out++;
					len += arrSmsLogs.get(i).getLength();
				}
			}
			if (out > 0) {
				this.outSmsTotal = (double) out / (double) arrSmsLogs.size();
				this.outSmsLenTotal = (double) len / (double) total;
				this.totalSmsLen = total;
			}
		}
	}

	public int getTotalSmsLen() {
		return totalSmsLen;
	}

	public void setTotalSmsLen(int totalSmsLen) {
		this.totalSmsLen = totalSmsLen;
	}

	public double getOutSmsTotal() {
		return outSmsTotal;
	}

	public void setOutSmsTotal(double outSmsTotal) {
		this.outSmsTotal = outSmsTotal;
	}

	public double getOutSmsLenTotal() {
		return outSmsLenTotal;
	}

	public void setOutSmsLenTotal(double outSmsLenTotal) {
		this.outSmsLenTotal = outSmsLenTotal;
	}

	public int getSms_length_total() {
		return sms_length_total;
	}

	public void setSms_length_total(int sms_length_total) {
		this.sms_length_total = sms_length_total;
	}

	public int[] getHour() {
		return hour;
	}

	public void setHour(int[] hour) {
		this.hour = hour;
	}

	public Contact getContactdetail() {
		return contactdetail;
	}

	public void setContactdetail(Contact contactdetail) {
		this.contactdetail = contactdetail;
	}

	public String getRelationshipLabelProcessed() {
		return relationshipLabelProcessed;
	}

	public double getOutgoingcall_totalprob() {
		return duroutgoingcall_totalprob;
	}

	public void setOutgoingcall_totalprob(double outgoingcall_totalprob) {
		this.duroutgoingcall_totalprob = outgoingcall_totalprob;
	}

	public double getIncomingcall_totalprob() {
		return durincomingcallVtotalprob;
	}

	public void setIncomingcall_totalprob(double incomingcall_totalprob) {
		this.durincomingcallVtotalprob = incomingcall_totalprob;
	}

	public double getOutgoingsms_totalProb() {
		return lenoutgoingsms_totalProb;
	}

	public void setOutgoingsms_totalProb(double outgoingsms_totalProb) {
		this.lenoutgoingsms_totalProb = outgoingsms_totalProb;
	}

	public double getIncomingsms_totalProb() {
		return lenincomingsmsVtotalProb;
	}

	public void setIncomingsms_totalProb(double incomingsms_totalProb) {
		this.lenincomingsmsVtotalProb = incomingsms_totalProb;
	}

	public double getSms_callProb() {
		return sms_callProb;
	}

	public void setSms_callProb(double sms_callProb) {
		this.sms_callProb = sms_callProb;
	}

	public void setRelationshipLabelProcessed(String relationshipLabelProcessed) {
		this.relationshipLabelProcessed = relationshipLabelProcessed;
	}

	public String getRelationshipLabel() {
		return relationshipLabel;
	}

	public void setRelationshipLabel(String relationshipLabel) {
		this.relationshipLabel = relationshipLabel;
	}

	public ArrayList<Call> getArrCallLogs() {
		return arrCallLogs;
	}

	public void setArrCallLogs(ArrayList<Call> arrCallLogs) {
		this.arrCallLogs = arrCallLogs;
	}

	public void addCallLogs(Call call) {
		this.arrCallLogs.add(call);
	}

	public void addSmsLogs(Sms sms) {
		this.arrSmsLogs.add(sms);
	}

	public ArrayList<Sms> getArrSmsLogs() {
		return arrSmsLogs;
	}

	public void setArrSmsLogs(ArrayList<Sms> arrSmsLogs) {
		this.arrSmsLogs = arrSmsLogs;
	}

	public double getProbabiltysms_call() {
		return probabiltysms_call;
	}

	public void setProbabiltysms_call(double probabiltysms_call) {
		this.probabiltysms_call = probabiltysms_call;
	}

	public int getSms_amount() {
		return sms_amount;
	}

	public void setSms_amount(int sms_amount) {
		this.sms_amount = sms_amount;
	}

	public int getCall_amount() {
		return call_amount;
	}

	public void setCall_amount(int call_amount) {
		this.call_amount = call_amount;
	}

	public double getSms_length_average() {
		return sms_length_average;
	}

	public void setSms_length_average(double sms_length_average) {
		this.sms_length_average = sms_length_average;
	}

	public double getCall_duration_average() {
		return call_duration_average;
	}

	public void setCall_duration_average(double call_duration_average) {
		this.call_duration_average = call_duration_average;
	}

	public String getMostdayinweek() {
		return mostdayinweek;
	}

	public void setMostdayinweek(String mostdayinweek) {
		this.mostdayinweek = mostdayinweek;
	}

	public String getMosthourinday() {
		return mosthourinday;
	}

	public void setMosthourinday(String mosthourinday) {
		this.mosthourinday = mosthourinday;
	}

	public void increaseSmsCount() {
		this.sms_amount++;
	}

	public void increaseCallCount() {
		this.call_amount++;
	}

	public double calcSmsLengthAverage() {
		double smslength = 0;
		if (arrSmsLogs != null) {
			for (int i = 0; i < arrSmsLogs.size(); i++) {
				smslength += arrSmsLogs.get(i).getLength();
			}
		}
		return this.sms_length_average = smslength / (arrSmsLogs.size() + 1);

	}

	public double calcCallDurationAverage() {
		double callDuration = 0;
		if (arrCallLogs != null) {
			for (int i = 0; i < arrCallLogs.size(); i++) {
				callDuration += arrCallLogs.get(i).getDuration();
			}
		}
		return this.call_duration_average = callDuration
				/ (arrCallLogs.size() + 1);

	}

	/**
	 * Tìm ngày liên lạc nhiều nhất trong tuần
	 * 
	 * @return
	 */
	public String calcMostDayInWeek() {
		Date date = null;
		int day[] = new int[8];
		for (int i = 0; i < 8; i++) {
			day[i] = 0;
		}
		for (int i = 0; i < arrCallLogs.size(); i++) {
			date = arrCallLogs.get(i).getDate();
			Calendar cal = new GregorianCalendar();
			cal.setTime(date);
			day[cal.get(Calendar.DAY_OF_WEEK)]++;
		}
		for (int i = 0; i < arrSmsLogs.size(); i++) {
			date = arrSmsLogs.get(i).getDate();
			Calendar cal = new GregorianCalendar();
			cal.setTime(date);
			day[cal.get(Calendar.DAY_OF_WEEK)]++;
		}

		int max = -1;
		int pos = 0;
		for (int i = 1; i <= 7; i++) {
			if (day[i] > max) {
				max = day[i];
				pos = i;
			}
		}

		if (pos == Calendar.SUNDAY) {
			return this.mostdayinweek = "3";
		} else if (pos == Calendar.SATURDAY) {
			return this.mostdayinweek = "2";
		} else if (pos == Calendar.SATURDAY) {
			return this.mostdayinweek = "1";
		} else {
			return this.mostdayinweek = "0";
		}
		// return this.mostdayinweek = String.valueOf(pos);
	}

	public String calcCallMostDayInWeek() {
		Date date = null;
		int day[] = new int[8];
		for (int i = 0; i < 8; i++) {
			day[i] = 0;
		}
		for (int i = 0; i < arrCallLogs.size(); i++) {
			date = arrCallLogs.get(i).getDate();
			Calendar cal = new GregorianCalendar();
			cal.setTime(date);
			day[cal.get(Calendar.DAY_OF_WEEK)]++;
		}
		int max = -1;
		int pos = 0;
		for (int i = 1; i <= 7; i++) {
			if (day[i] > max) {
				max = day[i];
				pos = i;
			}
		}

		if (pos == Calendar.SUNDAY) {
			return this.mostdayinweek = "3";
		} else if (pos == Calendar.SATURDAY) {
			return this.mostdayinweek = "2";
		} else if (pos == Calendar.SATURDAY) {
			return this.mostdayinweek = "1";
		} else {
			return this.mostdayinweek = "0";
		}
	}

	public String calcSmsMostDayInWeek() {
		Date date = null;
		int day[] = new int[8];
		for (int i = 0; i < 8; i++) {
			day[i] = 0;
		}
		for (int i = 0; i < arrSmsLogs.size(); i++) {
			date = arrSmsLogs.get(i).getDate();
			Calendar cal = new GregorianCalendar();
			cal.setTime(date);
			day[cal.get(Calendar.DAY_OF_WEEK)]++;
		}
		int max = -1;
		int pos = 0;
		for (int i = 1; i <= 7; i++) {
			if (day[i] > max) {
				max = day[i];
				pos = i;
			}
		}

		if (pos == Calendar.SUNDAY) {
			return this.mostdayinweek = "3";
		} else if (pos == Calendar.SATURDAY) {
			return this.mostdayinweek = "2";
		} else if (pos == Calendar.SATURDAY) {
			return this.mostdayinweek = "1";
		} else {
			return this.mostdayinweek = "0";
		}
	}

	public String calcMostHourOfDay() {
		if (arrCallLogs != null) {
			Time time = null;
			int hour[] = new int[24];
			int hourblock[] = new int[8];
			for (int i = 0; i < arrCallLogs.size(); i++) {
				time = arrCallLogs.get(i).getTime();
				Calendar cal = Calendar.getInstance();
				cal.setTime(time);
				hour[cal.get(Calendar.HOUR_OF_DAY)]++;
			}
			for (int i = 0; i < arrSmsLogs.size(); i++) {
				time = arrSmsLogs.get(i).getTime();
				Calendar cal = Calendar.getInstance();
				cal.setTime(time);
				hour[cal.get(Calendar.HOUR_OF_DAY)]++;
			}
			int k = 0;
			for (int j = 0; j < 24; j = j + 6) {
				for (int g = j; g < j + 6; g++) {
					hourblock[k] = hour[g]++;
				}
				k++;
			}
			int max = Integer.MIN_VALUE;
			int pos = 0;
			for (int i = 0; i < hourblock.length; i++) {
				if (hourblock[i] > max) {
					max = hourblock[i];
					pos = i;
				}
			}

			return this.mosthourinday = String.valueOf(pos);
		}
		// else {
		// return this.mosthourinday = "";
		// }
		return callmostdayinweek;

	}

	public void calcNumCallSMSCOMMSAtTimeOfDay() {
		int numCallMor = 0, numCallAft = 0, numCallEve = 0, numCallNig = 0;
		int durCallMor = 0, durCallAft = 0, durCallEve = 0, durCallNig = 0, totalDur = 0;

		// if (this.arrCallLogs != null && this.arrCallLogs.size() > 0) {

		for (int t = 0; t < this.arrCallLogs.size(); t++) {
			if (isNight(arrCallLogs.get(t).getTime())) {
				numCallNig++;
				durCallNig += arrCallLogs.get(t).getDuration();
			} else if (isEvening(arrCallLogs.get(t).getTime())) {
				numCallEve++;
				durCallEve += arrCallLogs.get(t).getDuration();
			} else if (isAfternoon(arrCallLogs.get(t).getTime())) {
				numCallAft++;
				durCallAft += arrCallLogs.get(t).getDuration();
			} else {
				numCallMor++;
				durCallMor += arrCallLogs.get(t).getDuration();
			}
			totalDur += arrCallLogs.get(t).getDuration();
		}
		this.numCallAtNight_Total = (double) numCallNig
				/ (double) this.arrCallLogs.size();
		this.numCallAtEvening_Total = (double) numCallEve
				/ (double) this.arrCallLogs.size();
		this.numCallAtMorning_Total = (double) numCallMor
				/ (double) this.arrCallLogs.size();
		this.numCallAtAfternoon_Total = (double) numCallAft
				/ (double) this.arrCallLogs.size();
		this.durCallAtNight_Total = (double) durCallNig / (double) totalDur;
		this.durCallAtEvening_Total = (double) durCallEve / (double) totalDur;
		this.durCallAtMorning_Total = (double) durCallMor / (double) totalDur;
		this.durCallAtAfternoon_Total = (double) durCallAft / (double) totalDur;
		// }
		// else {
		// this.numCallAtNight_Total = 0.0;
		// this.numCallAtEvening_Total = 0.0;
		// this.numCallAtMorning_Total = 0.0;
		// this.numCallAtAfternoon_Total = 0.0;
		// this.durCallAtNight_Total = 0.0;
		// this.durCallAtEvening_Total = 0.0;
		// this.durCallAtMorning_Total = 0.0;
		// this.durCallAtAfternoon_Total = 0.0;
		// }
		int numSmsMor = 0, numSmsAft = 0, numSmsEve = 0, numSmsNig = 0;
		int lenSmsMor = 0, lenSmsAft = 0, lenSmsEve = 0, lenSmsNig = 0, totalLen = 0;

		// if (this.arrSmsLogs != null && this.arrSmsLogs.size() > 0) {

		for (int t = 0; t < this.arrSmsLogs.size(); t++) {
			if (isNight(arrSmsLogs.get(t).getTime())) {
				numSmsNig++;
				lenSmsNig += arrSmsLogs.get(t).getLength();
			} else if (isEvening(arrSmsLogs.get(t).getTime())) {
				numSmsEve++;
				lenSmsEve += arrSmsLogs.get(t).getLength();
			} else if (isAfternoon(arrSmsLogs.get(t).getTime())) {
				numSmsAft++;
				lenSmsAft += arrSmsLogs.get(t).getLength();
			} else {
				numSmsMor++;
				lenSmsMor += arrSmsLogs.get(t).getLength();
			}
			totalLen += arrSmsLogs.get(t).getLength();
		}

		this.numSmsAtNight_Total = (double) numSmsNig
				/ (double) this.arrSmsLogs.size();
		this.numSmsAtEvening_Total = (double) numSmsEve
				/ (double) this.arrSmsLogs.size();
		this.numSmsAtMorning_Total = (double) numSmsMor
				/ (double) this.arrSmsLogs.size();
		this.numSmsAtAfternoon_Total = (double) numSmsAft
				/ (double) this.arrSmsLogs.size();

		this.lenSmsAtNight_Total = (double) lenSmsNig / (double) totalLen;
		this.lenSmsAtEvening_Total = (double) lenSmsEve / (double) totalLen;
		this.lenSmsAtMorning_Total = (double) lenSmsMor / (double) totalLen;
		this.lenSmsAtAfternoon_Total = (double) lenSmsAft / (double) totalLen;
		// }
		// else {
		// this.numSmsAtNight_Total = 0.0;
		// this.numSmsAtEvening_Total = 0.0;
		// this.numSmsAtMorning_Total = 0.0;
		// this.numSmsAtAfternoon_Total = 0.0;
		// this.lenSmsAtNight_Total = 0.0;
		// this.lenSmsAtEvening_Total = 0.0;
		// this.lenSmsAtMorning_Total = 0.0;
		// this.lenSmsAtAfternoon_Total = 0.0;
		// }

		this.numCommAtNight_Total = (double) (numSmsNig + numCallNig)
				/ (double) (this.arrSmsLogs.size() + this.arrCallLogs.size());
		this.numCommAtEvening_Total = (double) (numSmsEve + numCallEve)
				/ (double) (this.arrSmsLogs.size() + this.arrCallLogs.size());
		this.numCommAtMorning_Total = (double) (numSmsMor + numCallMor)
				/ (double) (this.arrSmsLogs.size() + this.arrCallLogs.size());
		this.numCommAtAfternoon_Total = (double) (numSmsAft + numCallAft)
				/ (double) (this.arrSmsLogs.size() + this.arrCallLogs.size());

	}

	public double getDurCallAtNight_Total() {
		return durCallAtNight_Total;
	}

	public double getDurCallAtEvening_Total() {
		return durCallAtEvening_Total;
	}

	public double getDurCallAtMorning_Total() {
		return durCallAtMorning_Total;
	}

	public double getDurCallAtAfternoon_Total() {
		return durCallAtAfternoon_Total;
	}

	public double getLenSmsAtNight_Total() {
		return lenSmsAtNight_Total;
	}

	public double getLenSmsAtEvening_Total() {
		return lenSmsAtEvening_Total;
	}

	public double getLenSmsAtMorning_Total() {
		return lenSmsAtMorning_Total;
	}

	public double getLenSmsAtAfternoon_Total() {
		return lenSmsAtAfternoon_Total;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public double getNumCommAtNight_Total() {
		return numCommAtNight_Total;
	}

	public double getNumCommAtEvening_Total() {
		return numCommAtEvening_Total;
	}

	public double getNumCommAtMorning_Total() {
		return numCommAtMorning_Total;
	}

	public double getNumCommAtAfternoon_Total() {
		return numCommAtAfternoon_Total;
	}

	public java.sql.Time get_6am() {
		return _6am;
	}

	public java.sql.Time get_12am() {
		return _12am;
	}

	public java.sql.Time get_12pm() {
		return _12pm;
	}

	public java.sql.Time get_0am() {
		return _0am;
	}

	public double getNumCallAtNight_Total() {
		return numCallAtNight_Total;
	}

	public double getNumSmsAtNight_Total() {
		return numSmsAtNight_Total;
	}

	public double getNumSmsAtEvening_Total() {
		return numSmsAtEvening_Total;
	}

	public double getNumSmsAtMorning_Total() {
		return numSmsAtMorning_Total;
	}

	public double getNumSmsAtAfternoon_Total() {
		return numSmsAtAfternoon_Total;
	}

	public void setNumCallAtNight_Total(double numCallAtNight_Total) {
		this.numCallAtNight_Total = numCallAtNight_Total;
	}

	public double getNumCallAtMorning_Total() {
		return numCallAtMorning_Total;
	}

	public void setNumCallAtMorning_Total(double numCallAtMorning_Total) {
		this.numCallAtMorning_Total = numCallAtMorning_Total;
	}

	public double getNumCallAtAfternoon_Total() {
		return numCallAtAfternoon_Total;
	}

	public void setNumCallAtAfternoon_Total(double numCallAtAfternoon_Total) {
		this.numCallAtAfternoon_Total = numCallAtAfternoon_Total;
	}

	public double getNumCallAtEvening_Total() {
		return numCallAtEvening_Total;
	}

	public void setNumCallAtEvening_Total(double numCallAtEvening_Total) {
		this.numCallAtEvening_Total = numCallAtEvening_Total;
	}

	java.sql.Time _6am = java.sql.Time.valueOf("06:00:00");
	java.sql.Time _12am = java.sql.Time.valueOf("12:00:00");
	java.sql.Time _6pm = java.sql.Time.valueOf("18:00:00");
	java.sql.Time _12pm = java.sql.Time.valueOf("23:59:59");
	java.sql.Time _0am = java.sql.Time.valueOf("00:00:00");

	public boolean isEvening(Time time) {
		if (time.after(_6pm) && time.before(_12pm)) {
			return true;
		}
		return false;
	}

	public boolean isMorning(Time time) {
		if (time.after(_6am) && time.before(_12am)) {
			return true;
		}
		return false;
	}

	public boolean isAfternoon(Time time) {
		if (time.after(_12am) && time.before(_6pm)) {
			return true;
		}
		return false;
	}

	public boolean isNight(Time time) {
		if (time.after(_0am) && time.before(_6am)) {
			return true;
		}
		return false;
	}

	public double smsCallProb() {
		if (this.call_amount != 0) {
			return this.sms_callProb = (double) (this.sms_amount / this.call_amount);
		}
		return 0;
	}

	public void calcDurOutgoingCallTotalProb() {
		int out_duration = 0, in_duration = 0;
		if (this.arrCallLogs != null) {
			for (int t = 0; t < this.arrCallLogs.size(); t++) {
				if (this.arrCallLogs.get(t).getCalltype().equals(Call.INCOMING)) {
					this.incomingcallamount++;
					out_duration += this.arrCallLogs.get(t).getDuration();
				} else if (this.arrCallLogs.get(t).getCalltype()
						.equals(Call.OUTGOING)) {
					this.outgoingcallamount++;
					in_duration += this.arrCallLogs.get(t).getDuration();
				} else if (this.arrCallLogs.get(t).getCalltype()
						.equals(Call.MISSED)) {
					this.misscallamount++;
				} else {
					this.failcallamount++;
				}

			}

			if (this.outgoingcallamount > 0 && out_duration > 0) {
				this.duroutgoingcall_totalprob = ((double) out_duration / (double) (out_duration + in_duration));
				this.failcall_outcall = (double) this.failcallamount
						/ (double) this.outgoingcallamount;
				this.misscall_incall = (double) this.misscallamount
						/ (double) this.incomingcallamount;

			}
			// else {
			// this.duroutgoingcall_totalprob = 0.0;
			// this.failcall_outcall = 0.0;
			// this.misscall_incall = 0.0;
			//
			// }
		}
		// else {
		// this.duroutgoingcall_totalprob = 0.0;
		// this.failcall_outcall = 0.0;
		// this.misscall_incall = 0.0;
		// }
	}

	public int getFailcallamount() {
		return failcallamount;
	}

	public void setFailcallamount(int failcallamount) {
		this.failcallamount = failcallamount;
	}

	public double getFailcall_outcall() {
		return failcall_outcall;
	}

	public void setFailcall_outcall(double failcall_outcall) {
		this.failcall_outcall = failcall_outcall;
	}

	public double getMisscall_incall() {
		return misscall_incall;
	}

	public int getIncomingcallamount() {
		return incomingcallamount;
	}

	public void setIncomingcallamount(int incomingcallamount) {
		this.incomingcallamount = incomingcallamount;
	}

	public int getOutgoingcallamount() {
		return outgoingcallamount;
	}

	public void setOutgoingcallamount(int outgoingcallamount) {
		this.outgoingcallamount = outgoingcallamount;
	}

	public int getIncomingsmsamount() {
		return incomingsmsamount;
	}

	public void setIncomingsmsamount(int incomingsmsamount) {
		this.incomingsmsamount = incomingsmsamount;
	}

	public int getOutgoingsmsamount() {
		return outgoingsmsamount;
	}

	public void setOutgoingsmsamount(int outgoingsmsamount) {
		this.outgoingsmsamount = outgoingsmsamount;
	}

	public int getMisscallamount() {
		return misscallamount;
	}

	public void setMisscallamount(int misscallamount) {
		this.misscallamount = misscallamount;
	}

	public double getDuroutgoingcall_totalprob() {
		return duroutgoingcall_totalprob;
	}

	public void setDuroutgoingcall_totalprob(double duroutgoingcall_totalprob) {
		this.duroutgoingcall_totalprob = duroutgoingcall_totalprob;
	}

	public double getDurincomingcall_totalprob() {
		return durincomingcallVtotalprob;
	}

	public void setDurincomingcall_totalprob(double durincomingcall_totalprob) {
		this.durincomingcallVtotalprob = durincomingcall_totalprob;
	}

	public double getLenoutgoingsms_totalProb() {
		return lenoutgoingsms_totalProb;
	}

	// {AVG,MAX} dur. {outgoing,incoming} calls
	double avg_dur_outgoing_call = 0.0, avg_dur_incoming_call = 0.0;
	int max_dur_outgoing_call = 0, max_dur_incoming_call = 0;

	public void calc_avg_max_dur_out_in_call() {
		// if (arrCallLogs.size() > 0) {
		DescriptiveStatistics outgoingCall = new DescriptiveStatistics();
		DescriptiveStatistics incomingCall = new DescriptiveStatistics();
		for (int i = 0; i < arrCallLogs.size(); i++) {
			if (arrCallLogs.get(i).getCalltype().equals(Call.OUTGOING)) {
				outgoingCall.addValue(arrCallLogs.get(i).getDuration());
			} else if (arrCallLogs.get(i).getCalltype().equals(Call.INCOMING)) {
				incomingCall.addValue(arrCallLogs.get(i).getDuration());
			}
		}

		// if (outgoingCall.getN() > 0) {
		this.avg_dur_outgoing_call = (double) outgoingCall.getMean();
		this.max_dur_outgoing_call = (int) outgoingCall.getMax();
		// }
		// else {
		// this.avg_dur_outgoing_call = 0;
		// this.max_dur_outgoing_call = 0;
		// }

		// if (incomingCall.getN() > 0) {
		this.avg_dur_incoming_call = (double) incomingCall.getMean();
		this.max_dur_incoming_call = (int) incomingCall.getMax();

		// }
		// else {
		// this.avg_dur_incoming_call = 0;
		// this.max_dur_incoming_call = 0;
		// }

		// }
		// else {
		// this.avg_dur_outgoing_call = 0;
		// this.max_dur_outgoing_call = 0;
		// this.avg_dur_incoming_call = 0;
		// this.max_dur_incoming_call = 0;
		//
		// }
		// System.out.println(this.avg_dur_outgoing_call + "-"
		// + this.max_dur_outgoing_call + "-" + this.avg_dur_incoming_call
		// + "-" + this.max_dur_incoming_call);
	}

	public double getAvg_dur_outgoing_call() {
		return avg_dur_outgoing_call;
	}

	public void setAvg_outgoing_call(double avg_outgoing_call) {
		this.avg_dur_outgoing_call = avg_outgoing_call;
	}

	public double getAvg_dur_incoming_call() {
		return avg_dur_incoming_call;
	}

	public void setAvg_incoming_call(double avg_incoming_call) {
		this.avg_dur_incoming_call = avg_incoming_call;
	}

	public int getMax_dur_outgoing_call() {
		return max_dur_outgoing_call;
	}

	public void setMax_outgoing_call(int max_outgoing_call) {
		this.max_dur_outgoing_call = max_outgoing_call;
	}

	public int getMax_dur_incoming_call() {
		return max_dur_incoming_call;
	}

	public void setMax_incoming_call(int max_incoming_call) {
		this.max_dur_incoming_call = max_incoming_call;
	}

	// {AVG, STD, MIN, MAX, MED} tổng số cuộc gọi {đến, đi} mỗi tuần;
	// tổng số ngày gọi/số ngày sử dụng; {AVG,MAX} thời lượng cuộc gọi {đến,
	// đi}.
	// {AVG, STD, MIN, MAX, MED} tổng số tin nhắn {đến, đi} mỗi tuần; tổng số
	// ngày nhắn tin/số ngày sử dụng;
	double avg_out_call_per_week = 0.0, std_out_call_per_week = 0.0,
			min_out_call_per_week = 0.0, max_out_call_per_week = 0.0,
			med_out_call_per_week = 0.0;
	double avg_in_call_per_week = 0.0, std_in_call_per_week = 0.0,
			min_in_call_per_week = 0.0, max_in_call_per_week = 0.0,
			med_in_call_per_week = 0.0;
	double avg_out_sms_per_week = 0.0, std_out_sms_per_week = 0.0,
			min_out_sms_per_week = 0.0, max_out_sms_per_week = 0.0,
			med_out_sms_per_week;
	double avg_in_sms_per_week = 0.0, std_in_sms_per_week = 0.0,
			min_in_sms_per_week = 0.0, max_in_sms_per_week = 0.0,
			med_in_sms_per_week = 0.0;
	private int numReplySms;
	private double numRepSmsVtotalProb;
	private int numDayLogs;
	private int numdaycomms;

	// Use to calc median std min max avg per week
	public void calc_AVG_STD_MIN_MAX_MED_SMS_CALL_per_Week() {
		int num_of_outsms_week[] = new int[47];// 30-46 =16
		int num_of_outcall_week[] = new int[47];
		int num_of_insms_week[] = new int[47];// 30-46 =16
		int num_of_incall_week[] = new int[47];
		if (arrSmsLogs != null) {
			// Get a DescriptiveStatistics instance
			DescriptiveStatistics outgoingSMS = new DescriptiveStatistics();
			DescriptiveStatistics incomingSMS = new DescriptiveStatistics();

			// Add the data from the array
			for (int j = 30; j < 47; j++) {
				for (int i = 0; i < arrSmsLogs.size(); i++) {
					if (arrSmsLogs.get(i).getSmstype().equals("Outgoing")
							&& arrSmsLogs.get(i).getWeek() == j) {
						num_of_outsms_week[j]++;
					}
					if (arrSmsLogs.get(i).getSmstype().equals("Incoming")
							&& arrSmsLogs.get(i).getWeek() == j) {
						num_of_insms_week[j]++;
					}
				}
				outgoingSMS.addValue(num_of_outsms_week[j]);
				incomingSMS.addValue(num_of_insms_week[j]);
			}
			if (outgoingSMS != null) {
				this.avg_out_sms_per_week = outgoingSMS.getMean();
				this.std_out_sms_per_week = outgoingSMS.getStandardDeviation();
				this.min_out_sms_per_week = outgoingSMS.getMin();
				this.max_out_sms_per_week = outgoingSMS.getMax();
				this.med_out_sms_per_week = outgoingSMS.getPercentile(50);
			}
			if (incomingSMS != null) {
				this.avg_in_sms_per_week = incomingSMS.getMean();
				this.std_in_sms_per_week = incomingSMS.getStandardDeviation();
				this.min_in_sms_per_week = incomingSMS.getMin();
				this.max_in_sms_per_week = incomingSMS.getMax();
				this.med_in_sms_per_week = incomingSMS.getPercentile(50);
			}
		}
		if (arrCallLogs != null) {
			DescriptiveStatistics outgoingCall = new DescriptiveStatistics();
			DescriptiveStatistics incomingCall = new DescriptiveStatistics();
			for (int j = 30; j < 47; j++) {
				for (int i = 0; i < arrCallLogs.size(); i++) {
					if (arrCallLogs.get(i).getCalltype().equals("Outgoing")
							&& arrCallLogs.get(i).getWeek() == j) {
						num_of_outcall_week[j]++;

					}
					if (arrCallLogs.get(i).getCalltype().equals("Incoming")
							&& arrCallLogs.get(i).getWeek() == j) {
						num_of_incall_week[j]++;

					}
				}
				outgoingCall.addValue(num_of_outcall_week[j]);
				incomingCall.addValue(num_of_incall_week[j]);

			}
			if (outgoingCall != null) {
				this.avg_out_call_per_week = outgoingCall.getMean();
				this.std_out_call_per_week = outgoingCall
						.getStandardDeviation();
				this.min_out_call_per_week = outgoingCall.getMin();
				this.max_out_call_per_week = outgoingCall.getMax();
				this.med_out_call_per_week = outgoingCall.getPercentile(50);
			}
			if (incomingCall != null) {
				this.avg_in_call_per_week = incomingCall.getMean();
				this.std_in_call_per_week = incomingCall.getStandardDeviation();
				this.min_in_call_per_week = incomingCall.getMin();
				this.max_in_call_per_week = incomingCall.getMax();
				this.med_in_call_per_week = incomingCall.getPercentile(50);
			}
		}

		// ----------------------------Compute some statistics
		// double mean = outgoing.getMean();
		// double std = outgoing.getStandardDeviation();
		// double median = outgoing.getPercentile(50);

	}

	public ArrayList getArrIncomingSMS() {
		return arrIncomingSMS;
	}

	public void setArrIncomingSMS(ArrayList arrIncomingSMS) {
		this.arrIncomingSMS = arrIncomingSMS;
	}

	public ArrayList getArrOutgoingSMS() {
		return arrOutgoingSMS;
	}

	public void setArrOutgoingSMS(ArrayList arrOutgoingSMS) {
		this.arrOutgoingSMS = arrOutgoingSMS;
	}

	public ArrayList getArrIncomingCall() {
		return arrIncomingCall;
	}

	public void setArrIncomingCall(ArrayList arrIncomingCall) {
		this.arrIncomingCall = arrIncomingCall;
	}

	public ArrayList getArrOutgoingCall() {
		return arrOutgoingCall;
	}

	public void setArrOutgoingCall(ArrayList arrOutgoingCall) {
		this.arrOutgoingCall = arrOutgoingCall;
	}

	public int getMaxDurIncomingCall() {
		return maxDurIncomingCall;
	}

	public void setMaxDurIncomingCall(int maxDurIncomingCall) {
		this.maxDurIncomingCall = maxDurIncomingCall;
	}

	public int getMaxDurOutgoingCall() {
		return maxDurOutgoingCall;
	}

	public void setMaxDurOutgoingCall(int maxDurOutgoingCall) {
		this.maxDurOutgoingCall = maxDurOutgoingCall;
	}

	public double getAvgIncomingSMS() {
		return avgIncomingSMS;
	}

	public void setAvgIncomingSMS(double avgIncomingSMS) {
		this.avgIncomingSMS = avgIncomingSMS;
	}

	public double getAvgOutgoingSMS() {
		return avgOutgoingSMS;
	}

	public void setAvgOutgoingSMS(double avgOutgoingSMS) {
		this.avgOutgoingSMS = avgOutgoingSMS;
	}

	public double getStdIncomingSMS() {
		return stdIncomingSMS;
	}

	public void setStdIncomingSMS(double stdIncomingSMS) {
		this.stdIncomingSMS = stdIncomingSMS;
	}

	public double getStdOutgoinSMS() {
		return stdOutgoinSMS;
	}

	public void setStdOutgoinSMS(double stdOutgoinSMS) {
		this.stdOutgoinSMS = stdOutgoinSMS;
	}

	public double getMinIncomingSMS() {
		return minIncomingSMS;
	}

	public void setMinIncomingSMS(double minIncomingSMS) {
		this.minIncomingSMS = minIncomingSMS;
	}

	public double getMinOutgoingSMS() {
		return minOutgoingSMS;
	}

	public void setMinOutgoingSMS(double minOutgoingSMS) {
		this.minOutgoingSMS = minOutgoingSMS;
	}

	public double getDurincomingcallVtotalprob() {
		return durincomingcallVtotalprob;
	}

	public void setDurincomingcallVtotalprob(double durincomingcallVtotalprob) {
		this.durincomingcallVtotalprob = durincomingcallVtotalprob;
	}

	public double getLenincomingsmsVtotalProb() {
		return lenincomingsmsVtotalProb;
	}

	public void setLenincomingsmsVtotalProb(double lenincomingsmsVtotalProb) {
		this.lenincomingsmsVtotalProb = lenincomingsmsVtotalProb;
	}

	public double getTotalCallV2WeekTotal() {
		return totalCallV2WeekTotal;
	}

	public void setTotalCallV2WeekTotal(double totalCallV2WeekTotal) {
		this.totalCallV2WeekTotal = totalCallV2WeekTotal;
	}

	public double getTotalCallV3MonthTotal() {
		return totalCallV2MonthTotal;
	}

	public void setTotalCallV3MonthTotal(double totalCallV3MonthTotal) {
		this.totalCallV2MonthTotal = totalCallV3MonthTotal;
	}

	public double getTotalSMSV2WeekTotal() {
		return totalSMSV2WeekTotal;
	}

	public void setTotalSMSV2WeekTotal(double totalSMSV2WeekTotal) {
		this.totalSMSV2WeekTotal = totalSMSV2WeekTotal;
	}

	public double getTotalSMSV3MonthTotal() {
		return totalSMSV2MonthTotal;
	}

	public void setTotalSMSV3MonthTotal(double totalSMSV3MonthTotal) {
		this.totalSMSV2MonthTotal = totalSMSV3MonthTotal;
	}

	public double getMedianOutgoingSMS() {
		return medianOutgoingSMS;
	}

	public void setMedianOutgoingSMS(double medianOutgoingSMS) {
		this.medianOutgoingSMS = medianOutgoingSMS;
	}

	public double getLengSMSinEveCompareTotal() {
		return lengSMSinEveCompareTotal;
	}

	public void setLengSMSinEveCompareTotal(double lengSMSinEveCompareTotal) {
		this.lengSMSinEveCompareTotal = lengSMSinEveCompareTotal;
	}

	public String getSmsmostdayinweek() {
		return smsmostdayinweek;
	}

	public void setSmsmostdayinweek(String smsmostdayinweek) {
		this.smsmostdayinweek = smsmostdayinweek;
	}

	public String getCallmostdayinweek() {
		return callmostdayinweek;
	}

	public void setCallmostdayinweek(String callmostdayinweek) {
		this.callmostdayinweek = callmostdayinweek;
	}

	public double getAvg_out_call_per_week() {
		return avg_out_call_per_week;
	}

	public void setAvg_out_call_per_week(double avg_out_call_per_week) {
		this.avg_out_call_per_week = avg_out_call_per_week;
	}

	public double getStd_out_call_per_week() {
		return std_out_call_per_week;
	}

	public void setStd_out_call_per_week(double std_out_call_per_week) {
		this.std_out_call_per_week = std_out_call_per_week;
	}

	public double getMin_out_call_per_week() {
		return min_out_call_per_week;
	}

	public void setMin_out_call_per_week(double min_out_call_per_week) {
		this.min_out_call_per_week = min_out_call_per_week;
	}

	public double getMax_out_call_per_week() {
		return max_out_call_per_week;
	}

	public void setMax_out_call_per_week(double max_out_call_per_week) {
		this.max_out_call_per_week = max_out_call_per_week;
	}

	public double getMed_out_call_per_week() {
		return med_out_call_per_week;
	}

	public void setMed_out_call_per_week(double med_out_call_per_week) {
		this.med_out_call_per_week = med_out_call_per_week;
	}

	public double getAvg_in_call_per_week() {
		return avg_in_call_per_week;
	}

	public void setAvg_in_call_per_week(double avg_in_call_per_week) {
		this.avg_in_call_per_week = avg_in_call_per_week;
	}

	public double getStd_in_call_per_week() {
		return std_in_call_per_week;
	}

	public void setStd_in_call_per_week(double std_in_call_per_week) {
		this.std_in_call_per_week = std_in_call_per_week;
	}

	public double getMin_in_call_per_week() {
		return min_in_call_per_week;
	}

	public void setMin_in_call_per_week(double min_in_call_per_week) {
		this.min_in_call_per_week = min_in_call_per_week;
	}

	public double getMax_in_call_per_week() {
		return max_in_call_per_week;
	}

	public void setMax_in_call_per_week(double max_in_call_per_week) {
		this.max_in_call_per_week = max_in_call_per_week;
	}

	public double getMed_in_call_per_week() {
		return med_in_call_per_week;
	}

	public void setMed_in_call_per_week(double med_in_call_per_week) {
		this.med_in_call_per_week = med_in_call_per_week;
	}

	public double getAvg_out_sms_per_week() {
		return avg_out_sms_per_week;
	}

	public void setAvg_out_sms_per_week(double avg_out_sms_per_week) {
		this.avg_out_sms_per_week = avg_out_sms_per_week;
	}

	public double getStd_out_sms_per_week() {
		return std_out_sms_per_week;
	}

	public void setStd_out_sms_per_week(double std_out_sms_per_week) {
		this.std_out_sms_per_week = std_out_sms_per_week;
	}

	public double getMin_out_sms_per_week() {
		return min_out_sms_per_week;
	}

	public void setMin_out_sms_per_week(double min_out_sms_per_week) {
		this.min_out_sms_per_week = min_out_sms_per_week;
	}

	public double getMax_out_sms_per_week() {
		return max_out_sms_per_week;
	}

	public void setMax_out_sms_per_week(double max_out_sms_per_week) {
		this.max_out_sms_per_week = max_out_sms_per_week;
	}

	public double getMed_out_sms_per_week() {
		return med_out_sms_per_week;
	}

	public void setMed_out_sms_per_week(double med_out_sms_per_week) {
		this.med_out_sms_per_week = med_out_sms_per_week;
	}

	public double getAvg_in_sms_per_week() {
		return avg_in_sms_per_week;
	}

	public void setAvg_in_sms_per_week(double avg_in_sms_per_week) {
		this.avg_in_sms_per_week = avg_in_sms_per_week;
	}

	public double getStd_in_sms_per_week() {
		return std_in_sms_per_week;
	}

	public void setStd_in_sms_per_week(double std_in_sms_per_week) {
		this.std_in_sms_per_week = std_in_sms_per_week;
	}

	public double getMin_in_sms_per_week() {
		return min_in_sms_per_week;
	}

	public void setMin_in_sms_per_week(double min_in_sms_per_week) {
		this.min_in_sms_per_week = min_in_sms_per_week;
	}

	public double getMax_in_sms_per_week() {
		return max_in_sms_per_week;
	}

	public void setMax_in_sms_per_week(double max_in_sms_per_week) {
		this.max_in_sms_per_week = max_in_sms_per_week;
	}

	public double getMed_in_sms_per_week() {
		return med_in_sms_per_week;
	}

	public void setMed_in_sms_per_week(double med_in_sms_per_week) {
		this.med_in_sms_per_week = med_in_sms_per_week;
	}

	public void setLenoutgoingsms_totalProb(double lenoutgoingsms_totalProb) {
		this.lenoutgoingsms_totalProb = lenoutgoingsms_totalProb;
	}

	public double getLenincomingsms_totalProb() {
		return lenincomingsmsVtotalProb;
	}

	public void setLenincomingsms_totalProb(double lenincomingsms_totalProb) {
		this.lenincomingsmsVtotalProb = lenincomingsms_totalProb;
	}

	public String relationshipLabelProcessing() {

		switch (Integer.parseInt(this.relationshipLabel)) {
		case 10:
			return this.relationshipLabelProcessed = "Xa_hoi";
		case 1000:
			return this.relationshipLabelProcessed = "Gia_dinh";
		case 100:
			return this.relationshipLabelProcessed = "Cong_viec";
		case 1:
			return this.relationshipLabelProcessed = "Ban_be";
		default:
			return this.relationshipLabelProcessed = this.relationshipLabel;
		}
	}

	public String relationshipLabelProcessing2() {

		switch (Integer.parseInt(this.relationshipLabel)) {
		case 1111:
			return this.relationshipLabelProcessed2 = "A";
		case 1001:
			return this.relationshipLabelProcessed2 = "GB";
		case 1100:
			return this.relationshipLabelProcessed2 = "GC";
		case 101:
			return this.relationshipLabelProcessed2 = "CB";
		case 1000:
			return this.relationshipLabelProcessed2 = "G";
		case 100:
			return this.relationshipLabelProcessed2 = "C";
		case 10:
			return this.relationshipLabelProcessed2 = "B";
		case 1:
			return this.relationshipLabelProcessed2 = "X";
		default:
			return this.relationshipLabelProcessed = this.relationshipLabel;
		}

	}

	public String getRelationshipLabelProcessed2() {
		return relationshipLabelProcessed2;
	}

	public void setRelationshipLabelProcessed2(
			String relationshipLabelProcessed2) {
		this.relationshipLabelProcessed2 = relationshipLabelProcessed2;
	}

	/**
	 * Kiem tra thoi gian (3 thang)
	 * 
	 * @param aDate
	 * @return
	 */
	public boolean checkTwoMonth(Date aDate) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, -2);
		return aDate.compareTo(calendar.getTime()) < 0;
	}

	/**
	 * Kiem tra thoi gian (2 tuan)
	 * 
	 * @param aDate
	 * @return
	 */
	public boolean checkTwoWeek(Date aDate) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, -14);
		return aDate.compareTo(calendar.getTime()) < 0;
	}

	/**
 * 
 */
	public void sortAscendingCallByDate() {
		Collections.sort(this.arrCallLogs, new Comparator<Call>() {

			@Override
			public int compare(Call c1, Call c2) {
				Date date1 = c1.getDate();
				Date date2 = c2.getDate();
				if (date1.equals(date2)) {
					return 0;
				} else if (date1.before(date2)) {
					return 1;
				} else {
					return -1;
				}
			}

		});
	}

	public void sortAscendingSmsByDate() {
		Collections.sort(this.arrSmsLogs, new Comparator<Sms>() {

			@Override
			public int compare(Sms c1, Sms c2) {
				Date date1 = c1.getDate();
				Date date2 = c2.getDate();
				if (date1.equals(date2)) {
					return 0;
				} else if (date1.before(date2)) {
					return 1;
				} else {
					return -1;
				}
			}

		});
	}

	public User() {

	}

	public User(Contact contact) {
		arrCallLogs = new ArrayList<>();
		arrSmsLogs = new ArrayList<>();
		this.contactdetail = contact;
	}

	public void calcNumReplySmsVTotalProb() {
		// if(arrSmsLogs!=null && arrSmsLogs.size() > 0){
		for (int p = 0; p < this.arrSmsLogs.size() - 1; p++) {
			for (int q = p + 1; q < this.arrSmsLogs.size(); q++) {
				if (arrSmsLogs.get(p).getDate()
						.equals(arrSmsLogs.get(q).getDate())
						&& arrSmsLogs.get(p).getSmstype().equals(Sms.OUTGOING)
						&& arrSmsLogs.get(q).getSmstype().equals(Sms.INCOMING)
						&& compareTwoTime(arrSmsLogs.get(p).getTime(),
								arrSmsLogs.get(p).getTime()) < 20) {
					this.numReplySms++;
				}
			}
		}

		this.numRepSmsVtotalProb = (double) this.numReplySms
				/ (double) this.sms_amount;
		// } else {
		// this.numRepSmsVtotalProb = 0.0;
		// }
	}

	public int getNumReplySms() {
		return numReplySms;
	}

	public void setNumReplySms(int numReplySms) {
		this.numReplySms = numReplySms;
	}

	public double getNumRepSmsVtotalProb() {
		return numRepSmsVtotalProb;
	}

	public void setNumRepSmsVtotalProb(double numRepSmsVtotalProb) {
		this.numRepSmsVtotalProb = numRepSmsVtotalProb;
	}

	public static long compareTwoTime(java.sql.Time currentTime,
			java.sql.Time oldTime) {
		long milliseconds1 = oldTime.getTime();
		long milliseconds2 = currentTime.getTime();

		long diff = Math.abs(milliseconds2 - milliseconds1);
		long diffSeconds = diff / 1000;
		long diffMinutes = diff / (60 * 1000);
		long diffHours = diff / (60 * 60 * 1000);
		long diffDays = diff / (24 * 60 * 60 * 1000);

		return diffMinutes;
	}

	public int getNumDayLogs() {
		return numDayLogs;
	}

	public void setNumDayLogs(int numDayLogs) {
		this.numDayLogs = numDayLogs;
	}

	public double getDayCallVDayLogged() {
		return (double) this.numdaycall / (double) numDayLogs;
	}

	public double getDaySmsVdayLogged() {
		return (double) this.numdaysms / (double) numDayLogs;
	}

	public double getDayCommsVdayLogged() {
		return (double) (this.numdaycomms) / (double) numDayLogs;
	}

	public double getNumdaycomms() {
		return numdaycomms;
	}

	public void setNumdaycomms(int numdaycomms) {
		this.numdaycomms = numdaycomms;
	}

}
